import React from 'react';
import { apiUrl } from '../utils/const';
import axios from 'axios';
import { useAuth } from '../context/auth-context';
function Login() {
    const { login, user } = useAuth();
    const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
        event.preventDefault();
        // 加as HTMLFormElement获取value
        const username = (event.currentTarget.elements[0] as HTMLFormElement)
            .value;
        const password = (event.currentTarget.elements[1] as HTMLFormElement)
            .value;
        login({
            username,
            password,
        });
    };
    return (
        <form onSubmit={handleSubmit}>
            <div>
                {user?.username ? `登录成功-用户名:${user.username}` : ''}
            </div>
            <div>
                <label htmlFor="username">用户名：</label>
                <input id="username" type="text" />
            </div>
            <div>
                <label htmlFor="password">密码：</label>
                <input id="password" type="password" />
            </div>
            <button type="submit">登录</button>
        </form>
    );
}

export default Login;
